package com.heima.controller;

import com.heima.pojo.dto.VmTypeDto;
import com.heima.pojo.dto.VmTypePageDto;
import com.heima.pojo.vo.VmTypePageVo;
import com.heima.service.VmTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/vm-service/vmType")
@Api("设备接口")
public class VmTypeController {

    @Autowired
    private VmTypeService vmTypeService;


    /**
     * 设备分页查询
     */
    @ApiOperation("设备分页查询")
    @GetMapping("/search")
    public VmTypePageVo pageQuery(VmTypePageDto dto){
        log.info("dto:{}",dto);
        VmTypePageVo vmTypePageVo = vmTypeService.pageQuery(dto);
        return vmTypePageVo;
    }

    /**
     * 新增设备类型
     */
    @PostMapping
    @ApiOperation("新增设备类型")
    public Boolean add(@RequestBody VmTypeDto dto){
        log.info("dto:{}",dto);
        vmTypeService.save(dto);
        return true;
    }

    /**
     * 修改设备
     */
    @ApiOperation("修改设备类型")
    @PutMapping("/{typeId}")
    public Boolean update(@PathVariable Integer typeId,@RequestBody VmTypeDto dto){
        log.info("id:{},dto:{}",typeId,dto);
        dto.setTypeId(typeId.toString());
        vmTypeService.save(dto);
        return true;
    }

    /**
     * 删除设备类型
     */
    @ApiOperation("删除设备类型")
    @DeleteMapping("/{typeId}")
    public Boolean delById(@PathVariable Integer typeId){
        log.info("id:{}",typeId);
        vmTypeService.delById(typeId);
        return true;
    }
}
